<?php
include("include/db.php");

$in_screen = (int)$_GET['screen'];
$in_film	= (int)$_GET['id'];


$result = mysql_query("SELECT * FROM films, screenings WHERE films.film_id = screenings.film_id AND screenings.screen_id = '$in_screen'  ", $db);
if($in_film != ''){
	$result = mysql_query("SELECT * FROM films, screenings WHERE films.film_id = screenings.film_id AND films.film_id = '$in_film'  ", $db);
	 	if(mysql_num_rows($result) == 0){	
			$result = mysql_query("SELECT * FROM films WHERE films.film_id = '$in_film'  ", $db);
		}	
}	

$myrow = mysql_fetch_array($result, MYSQL_ASSOC);

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html"/>
    <meta charset="utf-8">

    <title>Sebastopol Documentary Film Festival - <?php echo $myrow['title'];?></title>
    <script src="Scripts/AC_RunActiveContent.js" type="text/javascript">
</script>

<link type="text/css" href="main-events.css" rel="stylesheet" />


<style type="text/css">
	
	body{color: black;}
	
	a{color: black;}
	.clear{clear: both;}


    .style1 {color: #000000}
    .style3 {
    color: black;
    font-weight: bold;
    font-style: italic;
    }
    
    div.rightbody{
    	background-color: white;
    	color: black;
    
    }

</style>

</head>
<body class="sub">
<div id="container">
<div id="wrapper">
  <div id="left">
    <div class="logo">

    </div>
     	
     	<?php include "include/menu.php"; ?>
    
    <!-- end main nav -->
    <br class="clear" />
  </div>
  <!-- end left -->
  <div id="right">
    <div class="head">
    </div>
    <!-- end banner -->
    <div id="content">

                
                
           <h1><?php echo $myrow['title'];?><?php echo $myrow['event_title'];?></h1>
                <?php echo $myrow['director'];?> <?php if($myrow['year_produced'] != "0000"){echo $myrow['year_produced'];}?><br>
<?php  $x = 0;              
$result = mysql_query("SELECT * FROM film_cat, categories WHERE film_cat.film_id = '$in_film' AND film_cat.cat_id = categories.cat_id  ORDER BY categories.cat_name", $db);
if(mysql_num_rows($result) != 0){ ?>                
                <strong>Categories:</strong> 
<?php
                    while ($myrow1 = mysql_fetch_array($result, MYSQL_ASSOC)) { 
                    	if($x != 0){echo ", ";} echo $myrow1["cat_name"];
                    	 $x++; } ?>
<?php } ?>
                <hr>
                
            
                
                
                <div id="video_embed" style="float:left; margin: 0 10px 10px 0px;">
                	<?php echo $myrow['video_embed'];?>
                	<?php if($myrow['video_embed'] == '' && $myrow['thumbnail'] != ''){echo "<img src=\"$myrow[thumbnail]\" alt=\"$myrow[title]\">";}
                	
                	if($myrow[screen_thumb] != ''){echo "<img src=\"$myrow[screen_thumb]\" alt=\"$myrow[title]\">";}
                	?>
				</div>
				<br class="clear">
				
				<?php  if($myrow['type'] == 'f'){ ?>
				<hr>
				<h1>Screenings</h1>
				
				 <table width="65%" border="0" class="underline">

              <tbody>
              <?php
             
              
	$result2 = mysql_query("SELECT screenings.event_title, screenings.screen_id, screenings.date, screenings.time, screenings.type, venues.venue_name, venues.venue_id, films.title, films.film_id FROM screenings,venues,films WHERE screenings.venue_id = venues.venue_id AND screenings.film_id = films.film_id AND films.film_id = '$myrow[film_id]' ORDER BY screenings.date, screenings.time", $db);
      	while ($myrow2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { 
      	if($class == 'row2'){$class = 'row1';}else{$class = 'row2';}
      	if($current_day != $myrow2['date']){
      	   		$current_day = $myrow2['date'];
      	   		?>
      	   		<tr>
      	   			<td colspan="5"><h2><?php echo date("l, F j", strtotime($current_day));?></h2></td>
      	   		</tr>
      	   		<?php
      	   	}
      	
      		if($myrow2[type] == 'f'){
      		
      			$title = $myrow2[title];
      			$edit_link = "<a href=\"film_edit.php?id=$myrow2[film_id]\">$title</a>";
      		
      		
      		}
      		
      		
      		if($myrow2[type] == 'e'){
      		
      			$title = $myrow2[event_title];
      			$edit_link = "<a href=\"event_edit.php?id=$myrow2[screen_id]\">$title</a>";
      		
      		
      		}
      	
      	?>
      	
      	<tr class="<?php echo $class;?>">
      		<td width="10px"></td>
      		<td><?php echo date("g:i a", strtotime(substr($myrow2[time], 3)));?></td>
      		<td><a href="venue.php?id=<?php echo $myrow2['venue_id'];?>"><?php echo $myrow2['venue_name'];?></a></td>
      		<td><?php if($myrow2['ticket_link'] != ''){echo "<a href=\"$myrow2[ticket_link]\">Buy Tickets</a>";}?></td>
      	</tr>
            		  
   <?php $nolist = ''; }  ?>              

                </tr>
              </tbody>
            </table>
		<hr>		
			
                <?php } ?>

				
				
					<h3>Info</h3>
					<?php
					 if($myrow['video_embed'] != '' && $myrow['thumbnail'] != ''){echo "<img src=\"$myrow[thumbnail]\" alt=\"$myrow[title]\" align=\"right\" width=\"200\">";}?>
					
					<strong>Buy Tickets: </strong>
					<?php if($myrow['ticket_link'] != ''){echo "<a href=\"$myrow[ticket_link]\" target='_blank'>$ticket_image</a><br><br>";}
					if($myrow['film_web'] != ''){echo "<a href=\"$myrow[film_web]\" target='_blank'>Official Film Website</a>";}
					?>
					<br class="clear">
	
						<?php if( $myrow['runtime'] != ' '){?><p>Runtime: <?php echo $myrow['runtime'];?> min.<br> <?php } if($myrow['country'] != ' '){ ?> Origin: <?php echo $myrow['country']; }?></p>

				
				<?php echo $myrow['description'];?>
				<?php echo $myrow['event_desc'];?>
				<br>
				
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4cca21be5694d100"></script>


				
				<br>
				<?php
				$query2 = "SELECT screenings.event_title, screenings.screen_id, screenings.date, screenings.time, screenings.type, venues.venue_name, venues.venue_id, films.title, films.film_id, films.director, films.year_produced, films.runtime, films.ticket_link FROM screenings,venues,films, film_cat WHERE screenings.venue_id = venues.venue_id AND screenings.film_id = films.film_id AND films.film_id = film_cat.film_id AND screenings.date='$myrow[date]' AND screenings.time='$myrow[time]' AND screenings.venue_id='$myrow[venue_id]' AND screenings.film_id != '$myrow[film_id]' GROUP BY screenings.film_id ORDER BY screenings.date, screenings.time";
				//echo $query2;
						$result2 = mysql_query($query2, $db);
						if(mysql_num_rows($result2) != 0){ 
							echo "<h3>Screens With... </h3>";
	
						
					      	while ($myrow2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { 
					      	?>
					      	
					      	<a href="film.php?screen=<?php echo $myrow2[screen_id];?>"><?php echo $myrow2[title];?></a> <br>
      			<small><?php if($myrow2[type] == 'f'){ echo $myrow2['director']." ".$myrow2['year_produced']." | ".$myrow2['runtime']." min."; } ?></small><br>
					      		
					      <?php } } ?>	                
                
      <br class="clear" /> 
    </div><!-- end content -->
    <div id="footer">
   <p> &copy;2009 Sebastopol Center for the Arts and Trinity Productions. All rights reserved.</p>
    </div>
  </div><!-- end right -->
  </div><!-- end wrapper -->
  <br class="clear" />
</div><!-- end container -->
</body>
</html>
